package com.bsoft.quartz;

import com.bsoft.mapper.business.RegisterMapper;
import com.bsoft.service.HivPushService;
import com.bsoft.service.RegisterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**fixedRate/fixedRateString是按照固定的时间间隔（从任务开始的时间点计算）来执行任务的，
 * 而fixedDelay/fixedDelayString则是从上一次任务执行完成的时间点开始计算延迟时间。
 * */
@Component
public class ScheduledPutreslist {
    private Logger logger = LoggerFactory.getLogger(ScheduledPutreslist.class);

    @Autowired
    private RegisterService registerService;
    @Autowired
    private HivPushService hivPushService;

    @Value("${ghch}")
    private String ghch;

    @Value("${mzghStart}")
    private String mzghStart;

    @Value("${mzsfStart}")
    private String mzsfStart;

    @Value("${zyjsStart}")
    private String zyjsStart;

    @Value("${wechatUrlSendMsgStart}")
    private String wechatUrlSendMsgStart;

    @Value("${hivPushProviceLOg}")
    private String hivPushProviceLOg;

    @Value("${getLCLJLog}")
    private String getLCLJLog;

    @Value("${zhzyfSettPreLog}")
    private String zhzyfSettPreLog;




    /**initialDelay 表示程序启动5* 1000秒后开始执行任务*/
    //门诊挂号电子票据上传 @Scheduled(fixedRate = 300000)*/
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${dzpjSCTime}")
    public void invEBillRegistrationAll() {
        if ("1".equals(mzghStart)) {
            registerService.invEBillRegistration();
        }

    }

    //门诊收费电子票据上传 @Scheduled(fixedRate = 300000)
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${dzpjSCTime}")
    public void invoiceEBillOutpatientAll() {
        if ("1".equals(mzsfStart)) {
            registerService.invoiceEBillOutpatient();
        }
    }

    //住院结算电子票据上传 @Scheduled(fixedRate = 300000)
    @Scheduled(initialDelay = 3* 1000, fixedDelayString = "${dzpjSCTime}")
    public void invEBillHospitalizedAll() {
        if ("1".equals(zyjsStart)) {
            registerService.invEBillHospitalized();
        }
    }

    /**
     * 挂号电子票据冲红
     */
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${dzpjSCTime}")
    public void registerETicketRed() {
        if ("1".equals(ghch)) {
            registerService.registerETicketRed();
        }
    }

    /**
     * 省骨科合理用药推送微信
     */
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${dzpjSCTime}")
    public void medicationPush_Wechat() {
        if ("1".equals(wechatUrlSendMsgStart)) {
            logger.error("进入用药推送");
            registerService.medicationPush_Wechat();
        }
    }

    /**
     * 省骨科:定时从三方获取临床路径执行结果  getClinicalPathwaysExecutionResult
     */
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${dzpjSCTime}")
    public void getClinicalPathwaysExecutionResult() {
        if ("1".equals(getLCLJLog)) {
            logger.error("获取临床路径执行结果");
            registerService.getClinicalPathwaysExecutionResult();
        }
    }


    /**省骨科HIV上传省平台*/
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${hivSCTime}")
    public void push_HIVProvincePt() {
        if ("1".equals(hivPushProviceLOg)) {
            try {
                hivPushService.hivPush_ProvincePt();
            }catch (Exception e){
                logger.error("HIV上传省平台异常:",e);
            }
        }
    }

    /*智慧药房:已缴费处方推送:发送门诊药房处方 给整盒发药系统:Outpatientorder
    * 只推送当天已缴费的,按照缴费时间来
    * */
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${zhxyfSettPrePushTime}")
    public void push_zhzyf_settPre() {
        if ("1".equals(zhzyfSettPreLog)) {
            try {
                registerService.zhzyfPush_settPre();
            }catch (Exception e){
                logger.error("智慧中药房已缴费处方推送:",e);
            }
        }
    }

    /*
     * 省骨科发药机信息推送微信公众号: 发药窗口
     */
    @Scheduled(initialDelay = 5* 1000, fixedDelayString = "${zhxyfSettPrePushTime}")
    public void medicineMachinePush_Wechat() {
        if ("1".equals(zhzyfSettPreLog)) {
            logger.error("进入发药机窗口信息推送微信公众号推送");
            registerService.medicineMachinePush_Wechat();
        }
    }

}
